package com.springlearn.springsourcecode.chap5;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.*;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Set;

/**
 * @author wtcode
 * @Description
 * @date 2025/3/27 - 17:58
 */
public class A05Application {

    private static final Logger log = LoggerFactory.getLogger(A05Application.class);

    public static void main(String[] args) throws IOException {
        // 这是一个干净的容器
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean("config",Config.class);
        //context.registerBean("config2",Config2.class);

        context.registerBean(ConfigurationClassPostProcessor.class);  // @ComponentScan  @Bean @Import @ImportResource
        //context.registerBean(MapperScannerConfigurer.class,beanDefinition -> {
        //    beanDefinition.getPropertyValues().add("basePackage","com.springlearn.springsourcecode.chap5.mapper");  // @MapperScanner
        //}); // MapperScanner注解

        //context.registerBean(ComponentScannerPostProcessor.class);  // 扫描component
        //context.registerBean(AtBeanPostProcessor.class);  // 扫描@Bean
        context.registerBean(MapperPostProcessor.class); // 扫描@Mapper

        // 初始化容器
        context.refresh();

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
        // 销毁容器
        context.close();
    }
}
